/*
 * 文件名：UserServiceImpl.java
 * 版权：Copyright by www.wootide.com
 * 描述：用户业务层接口的实现类
 * 修改人：lizl
 * 修改时间：2012-9-12
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */
package com.wootide.cms.manager.service.impl;

import java.util.List;

import org.apache.log4j.Logger;

import com.wootide.cms.common.manager.SHException;
import com.wootide.cms.manager.dao.IUserDAO;
import com.wootide.cms.manager.pojo.User;
import com.wootide.cms.manager.service.IUserService;


/**
 * 〈一句话功能简述〉:用户业务层接口的实现
 * 〈功能详细描述〉
 * 在业务层，根据需求调用DB层的具体实现：
 * 【注意】：
 *  1.该异常在Action层进行异常捕获，并且做相应处理；
 *  2.对象msg：根据相应飞业务需求，反馈不同的异常信息，由开发人员根据业务需求进行定义；
 * @author lizl
 * @version 2012-9-12
 * @see UserServiceImpl
 * @since
 */

public class UserServiceImpl implements IUserService
{
    /**
     * DB层接口：业务层通过DB层对数据进行操作；
     */
    private IUserDAO userDAO;
    
    /**
     * 对业务层操作进行日志跟踪记录
     */
    private static final Logger LOGGER = Logger.getLogger(UserServiceImpl.class);
    
    /***
     * @return Returns the userDAO.
     */
    public IUserDAO getUserDAO()
    {
        return userDAO;
    }
    
    /***
     * @param userDAO The userDAO to set.
     */
    public void setUserDAO(IUserDAO userDAO)
    {
        this.userDAO = userDAO;
    }
    
    /** (non-Javadoc):增加用户
     * @see com.wootide.smarthotel.service.IUserService#addUser(com.wootide.smartclub.base.pojo.User)
     */
    
    public boolean addUser(User user) throws SHException
    {
        try
        {
            userDAO.insertUser(user);
        }
        catch (Exception e)
        {
            String msg = "增加用户不成功！请检测用户信息或其他信息！";
            LOGGER.error(msg, e);
            throw new SHException(msg, e);
        }
        return true;
    }
    
    /** (non-Javadoc)：查询多个对象
     * @see com.wootide.smarthotel.service.IUserService#getUser(com.wootide.smartclub.base.pojo.User)
     */
    
    public int getUserCount(User user) throws SHException
    {
        try
        {
            LOGGER.debug("");
            return userDAO.queryUser(user);
        }
        catch (Exception e)
        {
            String msg = "查询用户不成功！请检查查询条件是否符合要求，或其他操作！";
            LOGGER.error(msg, e);
            throw new SHException(msg, e);
        }
    }
    
    /** (non-Javadoc)：查询单个对象
     * @see com.wootide.smarthotel.service.IUserService#getUserById(com.wootide.smartclub.base.pojo.User)
     */
    
    public User getUserById(User user) throws SHException
    {
        try
        {
            return userDAO.queryUserById(user);
        }
        catch (Exception e)
        {
            String msg = "查询用户不成功！请检查输入查询条件是否符合,或其他！";
            LOGGER.error(msg, e);
            throw new SHException(msg, e);
        }
    }
    
    /** (non-Javadoc)：给用户授权
     * @see com.wootide.smarthotel.service.IUserService#grantUser(com.wootide.smartclub.base.pojo.User)
     */
    
 /*   public boolean grantUser(User user, Role role) throws SHException
    {
        try
        {
            userDAO.grantUser(user, role);
        }
        catch (Exception e)
        {
            String msg = "授权不成功！请检查当前操作用户是否有相关权限！";
            LOGGER.error(msg, e);
            throw new SHException(msg, e);
        }
        return true;
    }*/
    
    /** (non-Javadoc)：修改用户
     * @see com.wootide.smarthotel.service.IUserService#modUser(com.wootide.smartclub.base.pojo.User)
     */
    
    public boolean modUser(User user) throws SHException
    {
        try
        {
            userDAO.updateUser(user);
        }
        catch (Exception e)
        {
            String msg = "修改用户不成功！请检查修改信息是否符合条件，或是否有相关权限！";
            LOGGER.error(msg, e);
            throw new SHException(msg, e);
        }
        return true;
    }
    
    /** (non-Javadoc)：启用某个用户
     * @see com.wootide.smarthotel.service.IUserService#startUser(com.wootide.smartclub.base.pojo.User)
     */
    
    public boolean startUser(User user) throws SHException
    {
        try
        {
            userDAO.startUser(user);
        }
        catch (Exception e)
        {
            String msg = "启用当前用户不成功！";
            LOGGER.error(msg, e);
            throw new SHException(msg, e);
        }
        return true;
    }
    
    /** (non-Javadoc)：停用某个用户
     * @see com.wootide.smarthotel.service.IUserService#stopUser(com.wootide.smartclub.base.pojo.User)
     */
    
    public boolean stopUser(User user) throws SHException
    {
        try
        {
            userDAO.stopUser(user);
        }
        catch (Exception e)
        {
            String msg = "停用当前用户不成功！";
            LOGGER.error(msg, e);
            throw new SHException(msg, e);
        }
        return true;
    }
    
    /* (non-Javadoc)
     * @see com.wootide.smarthotel.service.IUserService#getUser(com.wootide.smarthotel.base.pojo.User, int, int)
     */
    public List<User> getUserList(User user, int start, int pageSize)
            throws SHException
    {
        return userDAO.getUserList(user, start, pageSize);
    }

    @Override
    public User getUser(User user) throws SHException
    {
        return userDAO.getUser(user);
    }

    @Override
    public List<User> getAllUsers() throws SHException
    {
        // TODO Auto-generated method stub
        return userDAO.getAllUsers();
    }

 
    
}
